/*
 * Copyright 2022 NXP
 * All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

/*********************
 *      INCLUDES
 *********************/
#include <stdio.h>
#include "lvgl/lvgl.h"
#include "events_init.h"

/*********************
 *      DEFINES
 *********************/

/**********************
 *      TYPEDEFS
 **********************/

/**********************
 *  STATIC PROTOTYPES
 **********************/

/**********************
 *  STATIC VARIABLES
 **********************/

/**
 * Create a demo application
 */

extern bool all_process_begin;
extern uint8_t detection_threshold;

static void btn_begin_event_handler (lv_event_t *e)
{
	lv_event_code_t code = lv_event_get_code(e);
	switch (code) {
	case LV_EVENT_PRESSED:
	{
		all_process_begin = 1;
		break;
	}
	default:
		break;
	}
}

static void slider_sensitivity_event_cb(lv_event_t * e)
{
	lv_obj_t * slider = lv_event_get_target(e);
	detection_threshold = (int)lv_slider_get_value(slider);
	lv_label_set_text_fmt(guider_ui.label_sen_num, "%d", detection_threshold);
}

void events_init(lv_ui *ui)
{
  /* Add your event callbacks here */
	lv_obj_add_event_cb(ui->btn_begin, btn_begin_event_handler, LV_EVENT_ALL, NULL);
	lv_obj_add_event_cb(ui->slider_sensitivity, slider_sensitivity_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
}
